import { get, post } from '@/utils/request'

// 定时任务相关接口
export const jobApi = {
  // 获取所有任务
  list: () => get('/jobApi/getAllJobs'),

  // 创建任务（body传参）
  create: (data) => post('/jobApi/createJob', data),

  // 触发执行一次（query传参）
  trigger: (jobName, jobGroup) => post('/jobApi/trigger', null, { params: { jobName, jobGroup } }),

  // 暂停任务
  pause: (jobName, jobGroup) => post('/jobApi/pause', null, { params: { jobName, jobGroup } }),

  // 恢复任务
  resume: (jobName, jobGroup) => post('/jobApi/resume', null, { params: { jobName, jobGroup } }),

  // 删除任务
  delete: (jobName, jobGroup) => post('/jobApi/delete', null, { params: { jobName, jobGroup } }),

  // 更新任务（仅支持更新cron与参数）
  update: (jobName, jobGroup, payload) =>
    post('/jobApi/update', payload, { params: { jobName, jobGroup } }),

  // 预览未来执行时间（返回未来5次）
  nextTimes: (jobCron) => post('/jobApi/getNextExecutionTimes', { jobCron }),
}

export default jobApi
